package com.ewzj.bigdata.mvp.presenter;

import android.app.Application;
import android.support.v7.widget.RecyclerView;

import com.ewzj.bigdata.app.utils.RxUtils;
import com.ewzj.bigdata.mvp.model.entity.resbean.SearchResult;
import com.ewzj.bigdata.mvp.model.entity.resbean.SearchResultBean;
import com.google.gson.Gson;
import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;

import javax.inject.Inject;

import com.ewzj.bigdata.mvp.contract.SearchContract;

import java.util.List;


@ActivityScope
public class SearchPresenter extends BasePresenter<SearchContract.Model, SearchContract.View> {
    private RxErrorHandler mErrorHandler;
    private Application mApplication;
    private ImageLoader mImageLoader;
    private AppManager mAppManager;
    private RecyclerView.Adapter mAdapter;
    private   List<SearchResult> mResults;
    private Gson mGson;
    @Inject
    public SearchPresenter(SearchContract.Model model, SearchContract.View rootView
            , RxErrorHandler handler, Application application
            , ImageLoader imageLoader, AppManager appManager,RecyclerView.Adapter adapter,List<SearchResult> results,Gson mGson) {
        super(model, rootView);
        this.mErrorHandler = handler;
        this.mApplication = application;
        this.mImageLoader = imageLoader;
        this.mAppManager = appManager;
        this.mAdapter=adapter;
        this.mGson=mGson;
        this.mResults=results;

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
        this.mAdapter=null;
        this.mResults=null;
    }
   public void loadHotSeach(){
       mModel.getHotSearch().compose(RxUtils.applySchedulers(mRootView))
               .subscribe(new ErrorHandleSubscriber<List<SearchResultBean>>(mErrorHandler) {
                   @Override
                   public void onNext(List<SearchResultBean> searchResultBeans) {
                        mRootView.showHotSearchData(searchResultBeans);
                   }
               });
   }

   public void saveHisData(SearchResultBean searchResultBean){
        mModel.saveSearchdata(searchResultBean);
   }

}
